#include "Universe.h"
#include "Scheduler.h"
#include "Shell.h"
#include "Ghost.h"
#include "Event.h"

unsigned int Shell::uniqueId = 1;

Shell::Shell(Universe * universe, Scheduler * scheduler, Ghost * ghost)
{
    this->universe = universe;
    this->scheduler = scheduler;
    this->ghost = ghost;
    this->event = new Event(this);
    
    active = false;
    
        id = uniqueId++;
}

Shell::~Shell()
{
    delete event;
}

void Shell::spawn()
{
    ghost->spawn();
}

void Shell::setActive(bool value)
{
    active = value;
}

void Shell::setPosition(const Position & position)
{
    this->position = position;
}

const Position & Shell::getPosition() const
{
    return position;
}

// what we can do (it's a bureaucracy)
bool Shell::requestMove(Direction & dir)
{
    if(universe->isOutsideUniverse(position, dir))
        return false;
    
    event->setPosition(position);
    event->addDirection(dir);
    scheduler->scheduleEvent(event);
    
    return true;
}

bool Shell::requestPosition(Position & pos)
{
    if(universe->isOutsideUniverse(position))
        return false;
    event->setPosition(position);
    scheduler->scheduleEvent(event);
    return true;
}

bool Shell::isActive()
{
    return active;
}

Ghost * Shell::getGhost()
{
    return ghost;
}


